<template>
  <div class="basic">
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <div class="page-left">
          <div class="hotel-name">
            <el-form-item label="酒店名称" prop="name">
                <el-input v-model="ruleForm.name" placeholder="请输入酒店名称"></el-input>
            </el-form-item>
          </div>
          <div class="hotel-aliases" v-for="(item, index) in HotelAlias">
            <el-form-item label="酒店别名" placeholder="请输入酒店别名">
              <el-input v-model="item.name" :disabled="true">
                <el-button slot="append" icon="el-icon-edit" @click="editItem(index)"></el-button>
                <el-button slot="append" icon="el-icon-delete" @click="deleteItem(index)" v-show="index !== 0"></el-button>
              </el-input>
            </el-form-item>
            <div class="add" @click="addItem(index)" v-show="index === 0">
                <el-button type="text">添加</el-button>              
            </div>
            <el-dialog title="添加酒店别名" :visible.sync="dialogFormVisible" width="20%">
                <el-form-item label="类别" width="60">
                  <el-select v-model="item.channel" placeholder="请选择类型">
                    <el-option label="美团" value="美团"></el-option>
                    <el-option label="携程" value="携程"></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="名称" width="60">
                  <el-input v-model="item.name" auto-complete="off"></el-input>
                </el-form-item>
                <el-form-item label="英文名" width="60">
                  <el-input v-model="item.enName" auto-complete="off"></el-input>
                </el-form-item>
              <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="save(index)">保存</el-button>
                <el-button @click="cancel">取 消</el-button>
              </div>
            </el-dialog>
          </div>
          <el-form-item label="酒店代码" prop="name" placeholder="请填写酒店代码">
              <el-input v-model="ruleForm.num"></el-input>
          </el-form-item>
          <el-form-item label="酒店地址" prop="region" placeholder="请填写酒店地址">
              <el-cascader
              :options="options"
              change-on-select
            ></el-cascader>
          </el-form-item>
          <el-form-item label="详细地址" prop="name" placeholder="请填写酒店详细地址">
              <el-input v-model="ruleForm.address"></el-input>
          </el-form-item>
          <el-form-item label="酒店网址" placeholder="请填写酒店网址">
              <el-input v-model="ruleForm.web"></el-input>
          </el-form-item>
          <el-form-item label="酒店标签" placeholder="请填写酒店标签">
              <el-input v-model="ruleForm.tag"></el-input>
          </el-form-item>
          <el-form-item label="邮政编码" placeholder="请填写邮政编码">
              <el-input v-model="ruleForm.zipCode"></el-input>
          </el-form-item>
          <div class="latitude-longitude">  
            <el-form-item label="经纬度" prop="name">
              <div class="input-left">
                <el-input v-model="ruleForm.lat" placeholder="请输入经度"></el-input>
                <label>经度</label>
              </div>
              <div class="input-right">
                <el-input v-model="ruleForm.lon" placeholder="请输入经度"></el-input>
                <label>纬度</label>
              </div>
            </el-form-item>
          </div>
        </div>
        <div class="page-right">
          <el-form-item label="英文名称" prop="name" placeholder="请填写酒店英文名">
              <el-input v-model="ruleForm.enName"></el-input>
          </el-form-item>
          <el-form-item label="酒店星级" prop="region">
              <el-select v-model="ruleForm.star" placeholder="请选择酒店星级">
              <el-option label="三星" value="shanghai"></el-option>
              <el-option label="四星" value="beijing"></el-option>
              <el-option label="五星" value="beijing"></el-option>
              </el-select>
          </el-form-item>
          <el-form-item label="酒店类型" prop="region">
              <el-select v-model="ruleForm.type" placeholder="请选择酒店类型">
              <el-option label="经济型" value="shanghai"></el-option>
              <el-option label="商务型" value="beijing"></el-option>
              <el-option label="豪华型" value="beijing"></el-option>
              </el-select>
          </el-form-item>
          <div class="call">
            <div class="input-left">
              <el-form-item label="总机电话">
                <el-input v-model="ruleForm.tel"></el-input>
              </el-form-item>
            </div>
            <div class="input-right">
              <el-form-item label="传真">
                <el-input v-model="ruleForm.fax"></el-input>
              </el-form-item>
            </div>
          </div>
          <el-form-item label="开业时间" placeholder="请选择开业时间"> 
            <el-date-picker
              v-model="ruleForm.openTime"
              type="date"
              placeholder="选择日期"
              default-value="2010-10-01">
            </el-date-picker>
          </el-form-item> 
          <el-form-item label="最后装修时间" placeholder="请选择最后一次装修时间"> 
            <el-date-picker
              v-model="ruleForm.lastRenovationTime"
              type="date"
              placeholder="选择日期"
              default-value="2010-10-01">
            </el-date-picker>
          </el-form-item> 
          <el-form-item label="客房数量" placeholder="请填写客房数量">
              <el-input v-model="ruleForm.roomNum"></el-input>
          </el-form-item>
          <el-form-item label="公司简介" placeholder="请填写公司简介">
              <el-input type="textarea" v-model="ruleForm.description"></el-input>
          </el-form-item>
        </div>
    </el-form>
    <div class="information-btn">
      <el-form-item>
          <el-button type="primary" @click="saveHotel">保存</el-button>
          <el-button>取消</el-button>      
      </el-form-item>
  </div>
  </div>
</template>
<script>
const ButtonFooter = () => import('@/components/common/ButtonFooter')
export default {
  name: 'BasicInformation',
  data () {
    return {
      dialogFormVisible: false,
      options: [{
        value: 'zhinan',
        label: '指南',
        children: [{
          value: 'zhinan',
          label: '指南'
        }]
      }],
      ruleForm: {
        num: '',
        fax: '',
        name: '',
        enName: '',
        star: '',
        address: '',
        web: '',
        tel: '',
        tag: '',
        openTime: '',
        lastRenovationTime: '',
        zipCode: '',
        roomNum: '',
        lat: '',
        lon: '',
        type: '',
        description: ''
      },
      HotelValue: [],
      HotelAlias: [
        {name: 'string', enName: 'string', channel: 'string'}
      ],
      rules: {
        name: [
          { required: true, message: '请输入活动名称', trigger: 'blur' },
          { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ],
        region: [
          { required: true, message: '请选择活动区域', trigger: 'change' }
        ],
        date1: [
          { type: 'date', required: true, message: '请选择日期', trigger: 'change' }
        ],
        date2: [
          { type: 'date', required: true, message: '请选择时间', trigger: 'change' }
        ],
        type: [
          { type: 'array', required: true, message: '请至少选择一个活动性质', trigger: 'change' }
        ],
        resource: [
          { required: true, message: '请选择活动资源', trigger: 'change' }
        ],
        desc: [
          { required: true, message: '请填写活动形式', trigger: 'blur' }
        ],
        none: [
          { trigger: 'blur' }
        ]
      }
    }
  },
  created () {
    if (sessionStorage.getItem('HotelId')) {
      const id = sessionStorage.getItem('HotelId')
      this.$http.post(window.commo.spUrl + '/hotel/info?token=' + window.commo.token, {timestamp: 0, version: 'string', operation: 'string', id: id}).then(res => {
        if (res.data.errCode) return false
        window.commo.hotelInformation = this.ruleForm = res.data.hotel
        this.HotelAlias = res.data.hotelAliases
        console.log(res.data)
      })
    }
  },
  methods: {
    cancel () {
      this.dialogFormVisible = false
    },
    submitForm (formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert('submit!')
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    resetForm (formName) {
      this.$refs[formName].resetFields()
    },
    addItem (index) {
      this.HotelAlias.push({name: ''})
    },
    deleteItem (index) {
      this.HotelAliases.splice(index, 1)
    },
    editItem (index) {
      this.dialogFormVisible = true
    },
    save (index) {
      this.HotelValue[index].name = this.HotelAlias[index].channel + ',' + this.HotelAlias[index].name + '(' + this.HotelAlias[index].enName + ')'
    },
    saveHotel () {
      const sendValue = {
        timestamp: 0,
        version: 'string',
        operation: 'string',
        hotelUpdateEntity: this.ruleForm,
        aliasEntities: this.HotelAlias
      }
      this.$http.post(window.commo.spUrl + 'salehotel/list?token=' + window.commo.token, sendValue).then(res => {
        if (res.data.errMsg > 0) {
          console.log(res.data.errMsg)
        }
      })
    }
  },
  components: {
    ButtonFooter
  }
}
</script>
<style lang="scss">
   .basic {
    margin-bottom: 30px;
    color: #415161;
    .page-left, .page-right {
      width: 45%;
      .el-form-item  {
        margin-bottom: 20px;
      }
    }
    .page-left {
      float: left;
      .hotel-aliases, .hotel-name {
        position: relative;
        .btn, .add {
          position: absolute;
          bottom: 0;
        }
        .add {
          right: -6%;
          top: 1%;
        }
        .btn {
          right: -10%;
        }
      }
    }
    .page-right {
      float: right;
      margin-right: 60px
    }
  }
  .el-cascader, .el-select, .el-date-editor.el-input, .el-date-editor.el-input__inner {
    width: 100%;
  }
  .latitude-longitude {
    display: block;
    .input-left, .input-right {
      width: 50%;
      .el-input {
        width: 80%;
        float: left;
      }
      label {
        margin-left: -3%;
        font-size: 12px;
      }
    }
    .input-left {
      float: left;
    }
    .input-right {
      float: right;
      margin-right: -3%;
    }
  }
  .call {
    overflow: hidden;
    .input-left, .input-right {
      width: 50%;
    }
    .input-left {
      float: left;
    }
    .input-right {
      float: right;
    }
  }
  .hotel-aliases {
    .el-dialog__header {
      text-align: left;
      background-color: rgb(243, 245, 249);
    }
  }
  .dialog-footer {
    text-align: center;
  }
  .information-btn {
    padding: 8px 0px 8px 55px;
    text-align: left;
    position: fixed;
    bottom: 0;
    background-color: white;
    box-shadow: 0px -1px 4px rgba(0,0,0,0.1);
    width: 79.7%;
    z-index: 1000;
    .el-form-item {
      margin-bottom: 0;
      .el-form-item__content {
        margin-left: 0!important;
      }
      .el-button{
        width: 82px;
        height: 34px;
        padding: 0px;
      }
    }
  }
</style>
